import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import { NzMessageService } from 'ng-zorro-antd';
import { HttpClient, HttpParams } from '@angular/common/http';
import { UtilService } from './util.service';
@Injectable()
export class contentStoreService {
  constructor(
    private http: Http,
    private message: NzMessageService,
    private utilService: UtilService
  ) { }
  //url='http://localhost:4396'
  url = 'http://packetstore.arktao.com'
  syurl = 'http://lpp.arktao.com'
  private headers = new Headers({ 'Content-Type': 'application/json' });
  GetRecommendList(): Promise<any> {
    return this.http.get(`${this.url}/packet/GetRecommendList`).toPromise().then(res => {
      return res.json();
    })
  }
  UnitListByGuidList(guidlist): Promise<any> {
    return this.http.get(`${this.syurl}/Packet/PacketListByGuidList?PacketGuidList=${guidlist}`).toPromise().then(res => {
      return res.json();
    })
  }
  packetmsg(PK_PacketGuid): Promise<any> {
    return this.http.get(`${this.url}/packet/packetmsg/${PK_PacketGuid}`).toPromise().then(res => {
      return res.json();
    })
  }
  createErrMessage(errmsg): void {
    this.message.create('error', `${errmsg}`);
  }
  createBasicMessage(msg): void {
    this.message.info(msg);
  }
  Unit(PK_UnitGuid): Promise<any> {
    return this.http.get(`${this.syurl}/Packet/Packet/${PK_UnitGuid}`).toPromise().then(res => {
      return res.json();
    })
  }
  CoursewareList(PK_PacketGuid): Promise<any> {
    return this.http.get(`${this.syurl}/Courseware/CoursewareList/${PK_PacketGuid}`).toPromise().then(res => {
      return res.json();
    })
  }
  GotMyPacket(PacketGuid): Promise<any> {
    let UserGuid: string="c838af15-d7a9-424a-b096-a781aa657d1d";
    // this.utilService.getUserInfo().then(re => {
    //   if(re.status==1)UserGuid = re.userGuid
    // })
    let data = {
      PacketGuid: PacketGuid,
      UserGuid: UserGuid
    }
    const url = `${this.syurl}/MyPacket/GotMyPacket`;
    return this.http.post(url, data, { headers: this.headers })
      .toPromise()
      .then(res => { return res.json() })
  }
  MyPacketInfoByUser(PacketGuid){
    let UserGuid: string="c838af15-d7a9-424a-b096-a781aa657d1d";
    // this.utilService.getUserInfo().then(re => {
    //   if(re.status==1)UserGuid = re.userGuid
    // })
    return this.http.get(`${this.syurl}/MyPacket/MyPacketInfoByUser?PacketGuid=${PacketGuid}&UserGuid=${UserGuid}`).toPromise().then(res => {
      return res.json();
    })
  }
}